﻿

@model PagedList<View_Order>
@{
    ViewBag.Title = "订单列表";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    OrderMasterQueryModel paramModel = new OrderMasterQueryModel();
    if (ViewBag.paramModel != null)
    {
        paramModel = (OrderMasterQueryModel)ViewBag.paramModel;
    }
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();

}
<form id="S_Form" class="form-inline definewidth m20" action="@Url.Action("OrderMasterList", "OrderMaster")" method="get">
    <div class="form_query">
        <div>
            会员手机号：
            <input type="text" name="account_mobile" id="account_mobile" class="abc input-default" placeholder="" value="@paramModel.account_mobile">&nbsp;
        </div><div>
            料号MPN：
            <input type="text" name="mpn" id="mpn" class="abc input-default" placeholder="" value="@paramModel.mpn">&nbsp;
        </div>
        <div>
            供应商名字：
            <input type="text" name="supplier_name" id="supplier_name" class="abc input-default" placeholder="" value="@paramModel.supplier_name">&nbsp;
        </div>
        <div>
            订单号：
            <input type="text" name="order_NO" id="order_NO" class="abc input-default" placeholder="" value="@paramModel.order_NO">&nbsp;
        </div><div>
            订单来源：
            <select id="order_source" name="order_source">
                <option value="-10" @(paramModel.order_source == -10 ? "selected" : "")>全部</option>
                @{
                    dc = new Dictionary<string, string>();
                    MyEnumHelper.GetEnumItems(typeof(OrderSource)).ForEach(t =>
                    {
                        dc.Add(t.Value.ToString(), t.Description);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.order_source.ToString());
            </select>&nbsp;
        </div>
        <div>
            订单状态：
            <select id="order_status" name="order_status">
                <option value="-6" @(paramModel.order_status == -6 ? "selected" : "")>有效状态</option>
                <option value="-10" @(paramModel.order_status == -10 ? "selected" : "")>全部状态</option>
                @{
                    dc = new Dictionary<string, string>();
                    MyEnumHelper.GetEnumItems(typeof(OrderStatus)).ForEach(t =>
                    {
                        dc.Add(t.Value.ToString(), t.Description);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.order_status.ToString());
            </select>&nbsp;
        </div>
        <div>
            是否发货：
            <select id="is_send" name="is_send">
                <option value="-10" @(paramModel.is_send == -10 ? "selected" : "")>全部状态</option>
                @{
                    dc = new Dictionary<string, string>();
                    MyEnumHelper.GetEnumItems(typeof(IsSend)).ForEach(t =>
                    {
                        dc.Add(t.Value.ToString(), t.Description);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.is_send.ToString());
            </select>&nbsp;
        </div>
        <div>
            支付类型：
            <select id="pay_type" name="pay_type">
                <option value="-10" @(paramModel.pay_type == -10 ? "selected" : "")>全部类型</option>
                @{
                    dc = new Dictionary<string, string>();
                    YiYiTong.Rocket.Helper.EnumHelper.GetEnumItems(typeof(PayType)).ForEach(t =>
                    {
                        dc.Add(t.Value.ToString(), t.Description);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.pay_type.ToString());
            </select>&nbsp;
        </div>
        <div>
            是否支付：
            <select id="is_succ" name="is_succ">
                <option value="-10" @(paramModel.pay_type == -10 ? "selected" : "")>全部</option>
                @{
                    dc = new Dictionary<string, string>();
                    YiYiTong.Rocket.Helper.EnumHelper.GetEnumItems(typeof(PaySucc)).ForEach(t =>
                    {
                        dc.Add(t.Value.ToString(), t.Description);
                    });
                }
                @HtmlPagerHelper.ShowSelectOpton(dc, paramModel.is_succ.ToString());
            </select>&nbsp;
        </div>
        <div>
            下单时间：
            <input type="text" name="create_time_begin" class="calendar calendar-time" id="create_time_begin" value="@paramModel.create_time_begin.ToString(1)"> - <input type="text" name="create_time_end" class="calendar calendar-time" id="create_time_end" value="@paramModel.create_time_end.ToString(1)">&nbsp;

        </div>
        <div>
            支付时间：<input type="text" name="pay_succ_time_begin" class="calendar calendar-time" id="pay_succ_time_begin" value="@paramModel.pay_succ_time_begin.ToString(1)"> - <input type="text" name="pay_succ_time_end" class="calendar calendar-time" id="pay_succ_time_end" value="@paramModel.pay_succ_time_end.ToString(1)">&nbsp;

        </div>
        @*<div>
                自动关闭时间：
                <input type="text" name="pay_end_time_begin" class="calendar calendar-time" id="pay_end_time_begin" value="@paramModel.pay_end_time_begin.ToString(1)"> - <input type="text" name="pay_end_time_end" class="calendar calendar-time" id="pay_end_time_end" value="@paramModel.pay_end_time_end.ToString(1)">&nbsp;

            </div>*@
        <div>
            @{Html.RenderPartial(Url.Content("~/Views/Common/PageSize.cshtml"), paramModel);}
        </div><div>
            <button type="submit" class="btn btn-primary" id="formsubmit">查询</button>&nbsp;&nbsp;<button type="button" class="btn btn-primary" id="downloadexcel">下载表格</button>
        </div>
    </div>
</form>

<table class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th>订单号</th>
            <th>会员手机号</th>
            <th>订单金额</th>
            <th>订单状态</th>
            <th>下单时间</th>
            @*<th>是否支付</th>*@
            <th>支付类型</th>
            <th>支付时间</th>
            <th>关闭支付时间</th>
            <th>是否发货</th>
            <th>是否申请退款</th>
            <th>收货人</th>
            <th>发票信息</th>
            <th>操作</th>
        </tr>
    </thead>
    @if (Model != null && Model.Count != 0)
    {
        int index = 0;
        foreach (var m in Model)
        {
            index++;
            <tr class="@HtmlPagerHelper.TrClass(index)">
                <td>@m.order_NO</td>
                <td>@m.account_mobile</td>
                <td>@m.total_money</td>
                <td>
                    @{
                        int order_status = ConvertHelper.ConvertTo<int>(m.order_status, 0);
                        switch (order_status)
                        {
                            case (int)OrderStatus.WaitPay:
                                @:<div>@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.PaySucc:
                                @:<div class="blue">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.Complete:
                                @:<div class="green">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                            case (int)OrderStatus.Cancel:
                                @:<div class="gray">@(MyEnumHelper.GetEnumItemDescription<OrderStatus>(order_status))</div>
                                break;
                        }
                    }
                </td>
                <td>@m.create_time.ToString(1)</td>
                @*<td>
                        @{
                            int is_succ = ConvertHelper.ConvertTo<int>(m.is_succ, 0);
                        }
                        @switch (is_succ)
                        {
                            case (int)PaySucc.NotPay:
                                @:<div class="red">@(MyEnumHelper.GetEnumItemDescription<PaySucc>(is_succ))</div>
                                break;
                            case (int)PaySucc.Paid:
                                @:<div class="green">@(MyEnumHelper.GetEnumItemDescription<PaySucc>(is_succ))</div>
                                break;
                        }
                    </td>*@

                <td>
                    @if (m.pay_type.HasValue)
                    {
                        <div>@(MyEnumHelper.GetEnumItemDescription<PayType>(ConvertHelper.ConvertTo<int>(m.pay_type, 1)))</div>
                    }
                </td>
                <td>@m.pay_succ_time.ToString(1)</td>
                <td>
                    @{
                        if (m.order_source.Value == (int)OrderSource.UserCreate
                            && m.is_succ.Value == (int)PaySucc.NotPay)
                        {
                            <div>@m.pay_end_time.ToString(1)</div>
                        }
                    }
                </td>
                <td>
                    @switch (m.is_send.Value)
                    {
                        case (int)IsSend.NotSend:
                            @:<div>@(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))</div>
                            break;
                        case (int)IsSend.Sended:
                            <div class="green">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))
                                <br />@m.send_time.ToString()
                            </div>
                            break;
                        case (int)IsSend.GetUseSelf:
                            <div class="orange">
                                @(MyEnumHelper.GetEnumItemDescription<IsSend>(m.is_send.Value))
                                <br />@m.send_time.ToString()
                            </div>
                            break;
                    }
                </td>
                <td>
                    @if (!m.is_apply_refund.HasValue)
                    {
                        m.is_apply_refund = 0;
                    }
                    @switch (m.is_apply_refund.Value)
                    {
                        case (int)IsApplyRefund.NotApply:
                            @:<div>@(MyEnumHelper.GetEnumItemDescription<IsApplyRefund>(m.is_apply_refund.Value))</div>
                            break;
                        case (int)IsApplyRefund.AlreadyApply:
                <div class="blue">
                    @{
                        var aDZ_RefundOrder = dbcontext.ADZ_RefundOrder.FirstOrDefault(t => t.order_master_id == m.order_id);
                        if (aDZ_RefundOrder != null)
                        {
                            <info>@(aDZ_RefundOrder.refund_amt)元 </info>
                            if (aDZ_RefundOrder.status == 2)
                            {
                                <info  class="green">退款完成</info>
                            }
                            else
                            {
                                if (aDZ_RefundOrder.tow_audit_status == 0)
                                {
                                    if (aDZ_RefundOrder.first_audit_status == 0)
                                    {
                                        <info>等待初审</info>
                                    }
                                    else if (aDZ_RefundOrder.first_audit_status == 1)
                                    {
                                        <info>初审通过 等待复审</info>
                                    }
                                    else if (aDZ_RefundOrder.first_audit_status == 2)
                                    {
                                        <info class="red">初审驳回</info>
                                    }
                                }
                                else if (aDZ_RefundOrder.tow_audit_status == 1)
                                {
                                    <info  class="green">复审通过</info>
                                }
                                else if (aDZ_RefundOrder.tow_audit_status == 2)
                                {
                                    <info class="red">复审驳回</info>
                                }
                            }
                        }
                    }


                </div>
                            break;
                    }
                </td>
                <td>@m.receiver [@m.receiver_telephone]</td>
                <td>
                    @switch (m.is_invoice)
                    {
                        case 0:
                            @:<div>不需要发票</div>
                            break;
                        case 1:
                            if (string.IsNullOrWhiteSpace(m.invoice_img))
                            {
                                <div class="red">发票资料未上传<br /> @m.invoice_title</div>
                            }
                            else
                            {
                                if (m.is_ready == 1)
                                {
                                    <div class="green">发票已开<br /> @m.invoice_title</div>
                                }
                                else
                                {
                                    <div class="red">发票未开<br /> @m.invoice_title</div>
                                }
                            }
                            break;
                    }
                </td>
                <td>
                    <a href="@Url.Action("OrderMasterInfo", "OrderMaster", new { id = m.order_id})" class="openbasetab">查看详情</a>
                    @if (m.is_succ == 1 && m.is_apply_refund == 0)
                    {
                        <a href="@Url.Action("refundinfo", "OrderMaster", new { id = m.order_id})">退款</a>
                    }
                    @if (m.order_status != (int)OrderStatus.Cancel)
                    {
                        <a href="@Url.Action("editprice", "OrderMaster", new { id = m.order_id})">改价</a>
                    }
                </td>
            </tr>
        }
        <tr>
            <td colspan="20"></td>
        </tr>
    }
</table>
<div class="inline pull-left total">
    总行数：@ViewData["AllCount"] | 总金额：@string.Format("{0:N2}", ViewData["total_money"])
</div>
<div class="inline pull-right page">
    @if (Model != null)
    {
        @Html.Pager(Model, HtmlPagerHelper.BasePagerOption)
    }
</div>
<script>
    var cancelButton =
        {
            text: '取消',
            elCls: 'button',
            handler: function () {
                this.close();
            }
        };
    reloadHandler = function ()
    {
        window.location.reload();
    }
    function setshow_min_level(id, show_min_level) {
        var op_name = "不可看";
        if (show_min_level == 0) {
            op_name = "可看";
        }
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该物料设为普通会员'+op_name+'吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("setshow_min_level", "product")";
                      parameter = {
                          id: id,
                          show_min_level: show_min_level
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    }

    function toWithdrawUp(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该物料上架吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("toWithdrawUp", "product")";
                      parameter = { id: id };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    }
        function toWithdrawDown(id) {
        BUI.Message.Show({
            title: '提示',
            msg: '确定要将该物料下架吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("toWithdrawDown", "product")";
                      parameter = { id: id };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
                },
                cancelButton
            ]
        });
    }

    function toWithdrawMore(withdraw) {
        var op_name = "下架";
        if (withdraw == 0) {
            op_name = "上架";
        }
        var ids = getCheckboxList();
        if (ids.length == 0) {
            BUI.Message.Alert("请选择要" + op_name+"的数据", 'warning');
            return;
        }

        BUI.Message.Show({
            title: '提示',
            msg: '确定要将选择的物料都' + op_name+'吗?',
            icon: 'question',
            buttons: [
              {
                  text: '确定',
                  elCls: 'button button-primary',
                  handler: function () {
                      url = "@Url.Action("toWithdrawMore", "product")";
                      parameter = {
                        withdraw: withdraw,
                        ids: ids
                      };
                      $.post(url, parameter, function (result) {
                          ShowActionResult(result, reloadHandler);
                      });
                      this.close();
                  }
              },
                cancelButton

            ]
        });
    }
        //下载列表
    $("#formsubmit").on("click", function () {
        $("#S_Form").attr("action", "@Url.Action("OrderMasterList", "OrderMaster")");
        $("#S_Form").submit();
    });

    //下载列表
    $("#downloadexcel").on("click", function () {
        $("#S_Form").attr("action", "@Url.Action("downOrderMasterList", "OrderMaster")");
        $("#S_Form").submit();
    });
</script>